package com.gaogzhen.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gaogzhen.domain.CashRecharge;
import com.gaogzhen.domain.CashWithdrawAuditRecord;
import com.gaogzhen.domain.CashWithdrawals;
import com.gaogzhen.model.CashSellParam;
import com.gaogzhen.service.CashWithdrawalsService;
import com.gaogzhen.utils.CurrentUser;
import com.gaogzhen.utils.R;
import com.gaogzhen.vo.CashTradeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author Administrator
 * @version 1.0
 * @description
 * @date 2022-11-10 11:49
 */
@RestController
@RequestMapping("/cashWithdrawals")
@Api(tags = "GCN提现控制器")
public class CashWithdrawalController {

    @Autowired
    private CashWithdrawalsService cashWithdrawalsService;

    @GetMapping("/records")
    @ApiOperation(value = "分页查询GCN提现记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="userId" ,value = "用户id"),
            @ApiImplicitParam(name ="username" ,value = "用户名"),
            @ApiImplicitParam(name ="mobile" ,value = "手机号"),
            @ApiImplicitParam(name ="status" ,value = "状态"),
            @ApiImplicitParam(name ="numMin" ,value = "提现金额下限"),
            @ApiImplicitParam(name ="numMax" ,value = "提现金额上限"),
            @ApiImplicitParam(name ="startTime" ,value = "开始时间"),
            @ApiImplicitParam(name ="endTime" ,value = "终止时间"),
            @ApiImplicitParam(name ="current" ,value = "当前页"),
            @ApiImplicitParam(name ="size" ,value = "每页条目"),
    })
    public R<Page<CashWithdrawals>> findByPage(
            Page<CashWithdrawals> page, Long userId, String username, String mobile, Byte status,
            String numMin, String numMax, String startTime, String endTime) {

        return R.ok(cashWithdrawalsService.findByPage(page, userId, username, mobile, status, numMin, numMax, startTime, endTime));
    }


    @GetMapping("/exportCNYWithDrawals")
    @ApiOperation(value = "导出GCN提现记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="userId" ,value = "用户id"),
            @ApiImplicitParam(name ="username" ,value = "用户名"),
            @ApiImplicitParam(name ="mobile" ,value = "手机号"),
            @ApiImplicitParam(name ="status" ,value = "状态"),
            @ApiImplicitParam(name ="numMin" ,value = "提现金额下限"),
            @ApiImplicitParam(name ="numMax" ,value = "提现金额上限"),
            @ApiImplicitParam(name ="startTime" ,value = "开始时间"),
            @ApiImplicitParam(name ="endTime" ,value = "终止时间"),
    })
    public void exportCNYWithDrawals(Long userId, String username, String mobile, Byte status,
            String numMin, String numMax, String startTime, String endTime) {
        cashWithdrawalsService.exportCNYWithDrawals(userId, username, mobile, status, numMin, numMax, startTime, endTime);
    }

    @PostMapping("/updateWithdrawalsStatus")
    @ApiOperation(value = "提现审核")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id")
    })
    public R updateWithdrawalsStatus(@RequestBody CashWithdrawAuditRecord auditRecord) {
        cashWithdrawalsService.updateWithdrawalsStatus(CurrentUser.getCurrentUserId(), auditRecord);
        return R.ok();
    }

    @GetMapping("/user/records")
    @ApiOperation(value = "查询当前用户提现记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="status" ,value = "状态"),
            @ApiImplicitParam(name ="current" ,value = "当前页"),
            @ApiImplicitParam(name ="size" ,value = "每页条目"),
    })
    public R<Page<CashWithdrawals>> findUserCashWithdrawals(Page<CashWithdrawals> page, Byte status) {
        return R.ok(cashWithdrawalsService.findUserCashWithdrawals(CurrentUser.getCurrentUserId(), page, status));
    }

    @PostMapping("/sell")
    @ApiOperation(value = "GCN卖出")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="cashSellParam" ,value = "cashSellParam json数据"),
    })
    public R sell(@RequestBody @Validated CashSellParam cashSellParam) {
        cashWithdrawalsService.sell(CurrentUser.getCurrentUserId(), cashSellParam);
        return R.ok();
    }
}
